package com.ict.web.controller.yzq;

import com.ict.common.annotation.Log;
import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.core.page.TableDataInfo;
import com.ict.common.enums.BusinessType;
import com.ict.common.utils.poi.ExcelUtil;
import com.ict.web.domain.SchemeDeclaration;
import com.ict.web.dto.SchemeDeclarationAddDto;
import com.ict.web.dto.SchemeDeclarationEditDto;
import com.ict.web.service.ISchemeDeclarationService;
import com.ict.web.vo.SchemeDeclarationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 方案申报--刘杰Controller
 *
 * @author ruoyi
 * @date 2022-02-25
 */
@Api(tags = "方案申报")
@RestController
@RequestMapping("/schemeDeclaration")
public class SchemeDeclarationController extends BaseController
{
    @Autowired
    private ISchemeDeclarationService schemeDeclarationService;

    /**
     * 查询方案申报--刘杰列表
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:list')")
    @ApiOperation("查询方案申报")
    @GetMapping("/list")
    public TableDataInfo list(SchemeDeclaration schemeDeclaration)
    {
        startPage();
        List<SchemeDeclaration> list = schemeDeclarationService.selectSchemeDeclarationList(schemeDeclaration);
        return getDataTable(list);
    }

    /**
     * 导出方案申报--刘杰列表
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:export')")
    @ApiOperation("导出方案申报")
    @Log(title = "方案申报--刘杰", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchemeDeclaration schemeDeclaration)
    {
        List<SchemeDeclaration> list = schemeDeclarationService.selectSchemeDeclarationList(schemeDeclaration);
        ExcelUtil<SchemeDeclaration> util = new ExcelUtil<SchemeDeclaration>(SchemeDeclaration.class);
        util.exportExcel(response, list, "方案申报--刘杰数据");
    }

    /**
     * 获取方案申报--刘杰详细信息
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:query')")
    @ApiOperation("获取方案申报")
    @GetMapping(value = "/{programmeId}")
    public SchemeDeclarationVo getInfo(@PathVariable("programmeId") Long programmeId)
    {
        return schemeDeclarationService.selectSchemeDeclarationByProgrammeId(programmeId);
    }

    /**
     * 新增方案申报--刘杰
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:add')")
    @ApiOperation("新增方案申报")
    @Log(title = "方案申报--刘杰", businessType = BusinessType.INSERT)
    @PostMapping
    public Long add(@Valid  @RequestBody SchemeDeclarationAddDto dto)
    {
        return schemeDeclarationService.insertSchemeDeclaration(dto);
    }

    /**
     * 修改方案申报--刘杰
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:edit')")
    @ApiOperation("修改方案申报")
    @Log(title = "方案申报--刘杰", businessType = BusinessType.UPDATE)
    @PutMapping("/edit/{programmeId}")
    public AjaxResult edit(@RequestBody SchemeDeclarationEditDto dto,@PathVariable Long programmeId)
    {
        return toAjax(schemeDeclarationService.updateSchemeDeclaration(dto,programmeId));
    }

    /**
     * 删除方案申报--刘杰
     */
//    @PreAuthorize("@ss.hasPermi('web:declaration:remove')")
    @ApiOperation("删除方案申报")
    @Log(title = "方案申报--刘杰", businessType = BusinessType.DELETE)
	@DeleteMapping("/{programmeId}")
    public AjaxResult remove(@PathVariable Long programmeId)
    {
        return toAjax(schemeDeclarationService.deleteSchemeDeclarationByProgrammeId(programmeId));
    }
}
